/**
* @author Jenny Windsperger, Stirling Pankow, Will Prew, Shane O'Malley-Potting
* @email jennifer.windsperger@my.uwrf.edu, stirling.pankow@my.uwrf.edu,
*        william.prew@my.uwrf.edu, shane.omalley-potting@my.uwrf.edu
* @date December 1st 2011
 */
package pongtests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import cs343.Ball;
import cs343.Paddle;

/**
 * 
 *
 */
public class BallTest {
	private static cs343.Ball ball1;
	private cs343.Ball ball2;
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ball1 = new Ball(400, 200, 10, 5, 270);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		ball2 = new Ball(400, 200, 10, 5, 90);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		ball2 = null;
	}

	/**
	 * Test method for {@link cs343.Ball#moveAhead(int)}.
	 */
	@Test
	public final void testMoveAhead() {
		ball2.moveAhead(10);
		assertEquals(ball2.getyPosition(), 200 +  (int) (10*Math.sin(Math.toRadians(ball2.getHeading()))), 10^-4  );
		ball2 = new Ball(400, 200, 10, 5, 90);
		ball2.moveAhead(10);
		assertEquals(ball2.getxPosition(), 400 +  (int) (10*Math.cos(Math.toRadians(ball2.getHeading()))), 10^-4  );
		ball2 = new Ball(400, 200, 10, 5, 90);
		ball2.moveAhead(-50);
		assertEquals(ball2.getyPosition(), 200 +  (int) (-50*Math.sin(Math.toRadians(ball2.getHeading()))), 10^-4  );
		ball2 = new Ball(400, 200, 10, 5, 90);
		assertEquals(ball2.getxPosition(), 400 +  (int) (-50*Math.cos(Math.toRadians(ball2.getHeading()))), 10^-4  );


	}

	/**
	 * Test method for {@link cs343.Ball#outOfBounds(int)}.
	 */
	@Test
	public final void testOutOfBounds() {
		ball2 = new Ball(400, 200, 10, 5, 90);
		assertEquals(ball2.outOfBounds(800), true);
		ball2 = new Ball(801, 200, 10, 5, 90);
		assertEquals(ball2.outOfBounds(800), false);
		ball2 = new Ball(-1, 200, 10, 5, 90);
		assertEquals(ball2.outOfBounds(800), false);

		
	}

	/**
	 * Test method for {@link cs343.Ball#checkCollision(int, int, cs343.Paddle)}.
	 */
	@Test
	public final void testCheckCollision() {
		cs343.Paddle paddle = new Paddle(20, 50, 175);
		ball2 = new Ball(0, 175, 10, 5, 180);
		ball2.checkCollision(400,800,paddle);
		assertEquals(ball2.getHeading(), 180 , 5);
		
		ball2 = new Ball(800, 175, 10, 5, 0);
		ball2.checkCollision(400,800,paddle);
		assertEquals(ball2.getHeading(), 0 , 5);

		
	
	
	}

}
